let loginEl = document.querySelector('.login')
let zhEl = document.querySelector('.zh')
let mmEL = document.querySelector('.mm')
let ztEl = document.querySelector('.zt')

loginEl.onclick = async function () {
  // 获取数据
  let tel = zhEl.value.trim()
  let password = mmEL.value.trim()
  let atLoneliness = ztEl.value

  if (!tel || !password) {
    return alert('内容不能为空')
  }
  let res = await axios({
    method: 'POST',
    url: 'http://localhost:8000/api/user/login',
    data: {
      tel,
      password,
      atLoneliness,
    }
  })
  console.log(res);

  let {
    code,
    msg,
    data
  } = res.data
  // 请求错误
  if (code) {
    return alert(msg)
  }

  // 存储当前用户的信息
  localStorage.user = JSON.stringify(data)
  // 跳转页面至首页
  location.href = './index.html'
}